<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="com.chilli.cosima.common.Auther" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
	<head>
		<base href="<%=basePath%>" />
		<title>Insert title here</title>
		<link href="css/validate.css" rel="stylesheet" type="text/css" />
		<link href="css/common.css" rel="stylesheet" type="text/css" />			
		<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
		<script src="js/jquery.tablesorter.min.js" type="text/javascript"></script>
		
	</head>
	<body>
	<div id="man_zone">
		<div class="navbar">
			客户管理 > 客户列表
		</div>
		<div class="toolbar">
			<%if (Auther.isPermitted(Auther.CUSTOMER_ADD)) {%>					
			<input type="button" value="增加" class="button_60" onMouseOver="this.className='button_60_over'" onMouseOut="this.className='button_60'" onclick="doAdd()" />
			<% }%>	
		</div>
 		
		<div class="main_content" >
			<s:form name="form" id="form" action="customer/customerQueryAction.action" method="post" theme="simple">	
			  <table id="tablesorter-list" class="tablesorter" border="0" cellpadding="0" cellspacing="1" align="center" id="myTable">
				<thead>
			   		<tr>
						<!-- <th>
							<input id="full" type="checkbox" onclick="seleAll(this)" />
						</th> -->
						<th>
							联系人名字
						</th>
						<th>
							姓
						</th>
						<th>
							名
						</th>
						<th>
							国籍
						</th>
						<th>
							生日
						</th>
                        <th>
                            操作
                        </th>
					</tr>
				</thead>
				<tbody>
				<s:iterator id="bean" value="#request.pagerBean.valueList">
					<tr>
						<!-- <td align="center">
							<input name="hotnums" type="checkbox"
								value="<s:property value="#bean.id" />"  onclick="changeCheckBox(this)" />
						</td> -->
						<td>
							<s:property value="#bean.name" />
						</td>
						<td>
							<s:property value="#bean.familyName" />
						</td>
						<td>
							<s:property value="#bean.givenName" />
						</td>
						<td>
							<s:property value="#bean.nationality" />
						</td>
                        <td>
                          <s:date name="#bean.birthday" format="yyyy-MM-dd" />
                        </td>
						<td>
							<%if (Auther.isPermitted(Auther.CUSTOMER_DETAIL)) {%>
							<span class="opt_span" onclick="doDetail('<s:property value="#bean.id" />')">客户明细</span>
							&nbsp;&nbsp;&nbsp;
							<% }%>
							<%if (Auther.isPermitted(Auther.CUSTOMER_EDIT)) {%>
							<span class="opt_span" onclick="doEdit('<s:property value="#bean.id" />')">客户修改</span>
							&nbsp;&nbsp;&nbsp;
							<% }%>
							<%if (Auther.isPermitted(Auther.CUSTOMER_DEL)) {%>
							<span class="opt_span" onclick="doDelete('<s:property value="#bean.id" />')">删除该客户</span>
							<% }%>
						</td>
					</tr>
				</s:iterator>
				</tbody>
				
				</table>
				<div class="pager_div"><%@ include file="/WEB-INF/jsp/pager.jsp"%></div>
		</s:form>
		</div>
	</div>
	</body>
	<script language="javascript">

		$(document).ready(function() {
		    $("#tablesorter-list").tablesorter();
		} );   

		function toggleAll(selector){ 
		    $(selector).each(function(){ 
		        this.checked = !this.checked; 
		    }) 
		}       	
		
		function doEdit(id) 
		{
        	var myForm = document.getElementById("form");
        	myForm.action = "customer/customerEditAction!jumpPage.action?id="+id;
            myForm.submit();
		}

		function doDetail(id) 
		{
        	var myForm = document.getElementById("form");
        	myForm.action = "customer/customerQueryAction!detail.action?id="+id;
            myForm.submit();
		}	
	
		function doAdd() 
		{
        	var myForm = document.getElementById("form");
        	myForm.action = "customer/customerAddAction!jumpPage.action";
            myForm.submit();
		}

		function doDelete(id) 
		{
			if(confirm("确认要删除该客户")) 
			{
	        	var myForm = document.getElementById("form");
	        	myForm.action = "customer/customerDelAction.action?id="+id;
	            myForm.submit();
			}

		}
	
		function doDeleteAll() 
		{

		    if(confirm("<s:text name='user.delete.confirm.all' />")) 
		    {
		    
		        if(confirm("<s:text name='user.delete.confirm.all.continue' />")) 
		        {
		        	var myForm = document.getElementById("form");
		        	myForm.action = "user/userDelAction.action";
		            myForm.submit();
		        }
		    }
		}

		function seleAll(obj)
		{
		    var status = obj.checked;
		    var sele = document.getElementsByName("hotnums");
		    
		    for(var i = 0 ; i < sele.length; i++)
		    {
		    
		        if(sele[i].checked != status && !sele[i].disabled)
		         {
		             sele[i].checked = status
		             changeCheckBox(sele[i]);//处理批量处理的复选框的状态
		         }
		    }
		}
		
		function changeCheckBox(node)
		{
		    var nodes=node.parentNode.parentNode.childNodes[3].childNodes;
		    var indexs=0;
		    if(node.checked)
		    {    
		        for(var i=0;i<nodes.length;i++)
		        {
		             if(nodes[i].type=="checkbox")
		             {
		                if(nodes[i].checked)//选中
		                {
		                    indexArr[i]++;    
		                }
		                else
		                {
		                    indexArr[i+1]++;
		                }
		             }
		        }
		    }
		    else
		    {
		        for(var i=0;i<nodes.length;i++)
		        {
		        
		             if(nodes[i].type=="checkbox")
		             {              
		             
		                if(nodes[i].checked && indexArr[i]>0)//选中
		                {
		                    indexArr[i]--;    
		                }
		                else if(indexArr[i+1]>0)
		                {
		                    indexArr[i+1]--;
		                }
		             }
		        }        
		    }
		}
	</script>
</html>